<% if user_signed_in? %>
  <% rating = ActsAsStarrable::Rating.find(:first, :conditions => {:rater_type => 'User', :rater_id => current_user.id, :starrable_type => starrable.class, :starrable_id => starrable.id}) %>
  <%= javascript_tag do %>
    window.rater = '<%= current_user.id %>';
    window.rater_type = '<%= current_user.class %>';
    window.rating = <%= rating ? rating.id : 'null' %>;
    window.starrable_type = '<%= starrable.class %>';
  <% end %>
<% end %>
<% if rating %>
  <div class="rateit" data-rateableid="<%= starrable.id %>" data-rateit-value="<%= rating.rating %>" data-rateit-ispreset="false"></div>
  <span itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">avg.
    <span itemprop="ratingValue"><%= starrable.average_rating %></span> stars out of
    <span itemprop="bestRating"><%= starrable.max_rating %></span>
    (<span itemprop="ratingCount"><%= pluralize(starrable.ratings.count, 'rating') %></span> total).
  </span>
<% else %>
  <div class="rateit" data-rateableid="<%= starrable.id %>" data-rateit-value="<%= starrable.average_rating %>" data-rateit-ispreset="true" data-rateit-resetable="false" data-rateit-readonly="<%= !user_signed_in? %>"></div>
  <span itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
    <span itemprop="ratingValue"><%= starrable.average_rating %></span> stars out of
    <span itemprop="bestRating"><%= starrable.max_rating %></span>
    (<span itemprop="ratingCount"><%= pluralize(starrable.ratings.count, 'rating') %></span> total).
  </span>
<% end %>